package com.loong.common.mybatis.tools;

import com.github.pagehelper.ISelect;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.loong.common.domain.BaseQuery;
import com.loong.common.domain.Pager;

public class PageTools {
    public static  <T> Pager<T> pageQuery(BaseQuery baseQuery, ISelect iSelect) {
        PageInfo<T> objects = PageHelper.startPage(baseQuery.getPageIndex(), baseQuery.getPageSize()).doSelectPageInfo(
                iSelect
        );
        return Pager.<T>builder()
                .dataList(objects.getList())
                .pageSize(objects.getPageSize())
                .pageIndex(baseQuery.getPageIndex())
                .total(objects.getTotal())
                .totalPage(objects.getPages())
                .build();
    }
}
